package com.example.userserver.manager;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.userserver.entity.UserInfo;
import com.example.userserver.mapper.UserInfoMapper;
import com.example.userserver.params.PageUserInfoParams;
import com.example.userserver.utils.BeanCopyUtils;
import com.example.userserver.vo.UserInfoVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

@Service
public class UserInfoManager {
    @Autowired
    private UserInfoMapper userInfoMapper;

    public void insertUserInfo(UserInfo userInfo){
        userInfoMapper.insert(userInfo);
    }

    public void deleteUserInfo(String id){
        userInfoMapper.deleteById(id);
    }

    public void updateUserInfo(UserInfo userInfo){
        userInfoMapper.updateById(userInfo);
    }

    public List<UserInfoVO> listUserInfo(PageUserInfoParams pageUserInfoParams){
        return userInfoMapper.pageUser(pageUserInfoParams);
    }

    public UserInfoVO getUserInfo(String id){
        return userInfoMapper.getUserVOById(id);
    }

    public UserInfo getUserInfoDO(String id){
        return userInfoMapper.selectById(id);
    }

    public boolean checkStudentId(String schoolId, String studentId) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("school_id", schoolId);
        queryWrapper.eq("student_id", studentId);
        UserInfo userInfo = userInfoMapper.selectOne(queryWrapper);
        if(ObjectUtil.isNotNull(userInfo)){
            return true;
        }
        return false;
    }

    public boolean checkUserName(String userName) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("user_name", userName);
        UserInfo userInfo = userInfoMapper.selectOne(queryWrapper);
        if(ObjectUtil.isNotNull(userInfo)){
            return true;
        }
        return false;
    }
}
